#ifndef SPYNET_NET_SINGLETON_H_
#define SPYNET_NET_SINGLETON_H_

namespace Net
{
	template <typename T> class Singleton
	{
    public:
       Singleton( void )
       {
           assert( !singleton_ );
#if defined( _MSC_VER ) && _MSC_VER < 1200
            int offset = (int)(T*)1 - (int)(Singleton <T>*)(T*)1;
            singleton_ = (T*)((int)this + offset);
#else
        singleton_ = static_cast<T*>(this);
#endif
        }

        ~Singleton( void )
        {
			assert(singleton_);
			singleton_ = 0;
		}

        static T& GetSingleton( void )
        {
			assert(singleton_);
			return *singleton_;
		}

        static T* GetSingletonPtr( void )
        {
			return singleton_;
		}

	private:
        static T* singleton_;

    };
}

#endif